import { Body, Controller, Get, Param, Post, Query } from "@nestjs/common";
import { addSong, getSongList, getSongLrc, getSongNow } from "src/dto/song.dto";
import { success } from "src/utils/common";
import { SongService } from "./song.service";

@Controller("song")
export class SongController {
  constructor(private songService: SongService) {}
  @Get("getSongList")
  async getSongList(@Query() songList: getSongList) {
    const res = await this.songService.getSongList(songList.room_id);
    if (res) {
      return success("查询成功", res);
    } else {
      return success("查询成功", []);
    }
  }

  @Get("Post")
  async addSong(@Body() info: addSong) {
    return await this.songService.addSong(info.room_id, info.rid, "");
  }

  @Get("searchSong")
  async searchSong() {
    const keyword = "周杰伦";
    return await this.songService.searchSong(keyword);
  }

  @Post("getSongLrc")
  async getSongLrc(@Body() info: getSongLrc) {
    return success("请求成功", await this.songService.getSongLrc(info.rid));
  }

  @Post("getSongUrl")
  async play(@Body() info: getSongNow) {
    const res = await this.songService.getSongUrl(info.rid);
    return success("请求成功", { url: res });
  }
}
